using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace OpenPanekitEditor.Forms
{
    public partial class PanelInitialPropertyDialog : Form
    {
        float LocalValueScale;
        Panel.Parameter param;
        public PanelInitialPropertyDialog(Panel.Parameter p)
        {
            InitializeComponent();
            param = p;
            LocalValueScale = 1f;
            for (int i = 0; i < 3; i++)
            {
                if (((param.Quantize * LocalValueScale) % 1f) < 0.0001)
                {
                    break;
                }
                LocalValueScale = LocalValueScale * 10f;
            }
            trackBar1.ValueChanged += new EventHandler(trackBar1_ValueChanged);
            trackBar1.Maximum = (int)(param.UpperLimit * LocalValueScale);
            trackBar1.Minimum = (int)(param.LowerLomit * LocalValueScale);
            trackBar1.TickFrequency = (int)(param.Quantize * LocalValueScale);
            this.Text = param.Title;
        }

        private void trackBar1_ValueChanged(object sender, EventArgs e)
        {
            trackBar1.Value = trackBar1.Value - (trackBar1.Value % (int)(param.Quantize * LocalValueScale));
            label1.Text = String.Format("{0} {1}", trackBar1.Value, param.Unit);
        }
        public float GetParameter()
        {
            return trackBar1.Value / LocalValueScale;
        }
    }
}